<div class="leftbody">
    <section class="col-md-8 col-sm-12 col-xs-12" ng-controller="regCtrl">
        <form name="regForm" ng-submit="processRegForm(regForm.$valid)" novalidate>
            <h3><a href="/">主页</a>/用户注册 &nbsp;<small class="text-danger hide" id="errorInfo">用户名已存在</small></h3>
            <div class="form-group">
                <input type="text" class="form-control" name="userName" id="userName" ng-minlength="6" ng-maxlength="12" ng-model="regFormData.userName" ng-pattern="/^[a-zA-Z][a-zA-Z0-9_]{5,11}$/" placeholder="请输入用户名" required>
                <label ng-cloak for="inputError" class="control-label text-danger" ng-show="regForm.userName.$invalid && !regForm.userName.$pristine"><i class="glyphicon glyphicon-exclamation-sign"></i>用户名为6-12个英文数字组合</label>
            </div>
            <div class="form-group">
                <input type="email" class="form-control" name="email" id="email" ng-model="regFormData.email" ng-pattern="/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/" placeholder="请输入邮箱地址" required>
                <label ng-cloak for="inputError" class="control-label text-danger" ng-show="regForm.email.$invalid && !regForm.email.$pristine"><i class="glyphicon glyphicon-exclamation-sign"></i>请输入正确的邮箱地址</label>
            </div>
            <div class="form-group">
                <input type="password" class="form-control" id="userPassword" name="password"placeholder="请输入密码" ng-pattern="/[?!a-zA-Z0-9_]{6,16}/" ng-maxlength="16" ng-model="regFormData.password" required>
                <label ng-cloak for="inputError" class="control-label text-danger" ng-show="regForm.password.$invalid && !regForm.password.$pristine"><i class="glyphicon glyphicon-exclamation-sign"></i>6-16位，只能包含字母数字下划线</label>
            </div>
            <div class="form-group">
                <input type="password" class="form-control" pw-check="userPassword" name="confirmPassword" placeholder="请再次输入密码" ng-model="regFormData.confirmPassword" ng-pattern="/[?!a-zA-Z0-9_]{6,16}/" ng-maxlength="16" required>
                <label ng-cloak for="inputError" class="control-label text-danger" ng-show="regForm.confirmPassword.$invalid && !regForm.confirmPassword.$pristine"><i class="glyphicon glyphicon-exclamation-sign"></i>两次输入的密码不匹配</label>
            </div>
            <div>
                <button class="btn btn-block btn-info" ng-disabled="regForm.$invalid">注册</button>
            </div>
        </form>
    </section>
    <section>
        <%- include rightmain%>
    </section>
</div>
<script>
    var webApp = angular.module('webApp',[]);
    webApp.controller("regCtrl",function($scope,$http){
        $scope.processRegForm = function(isVaild){
            if(isVaild){
                $http({
                    method:'POST',
                    url:'/users/doReg',
                    data: $.param($scope.regFormData),
                    headers:{'Content-Type':'application/x-www-form-urlencoded'}
                }).success(function(data){
                    if (data === "success") {
                        alert("注册成功,您现在可以登录")
                        window.location = "/users/login"
                    } else {
                        $('#errorInfo').removeClass('hide').text(data)
                    }
                })
            }
        }
    })
</script>